﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Xejen.Database.Exceptions
{
    /// <summary>
    /// 代表实体类不存在的异常
    /// </summary>
    [Serializable]
    public class EntityNotFoundException : SystemException
    {
        /// <summary>
        /// 表示实体类类型
        /// </summary>
        public Type EntityType { get; set; }

        /// <summary>
        /// 表示实体类的主键Id
        /// </summary>
        public object Id { get; set; }

        /// <inheritdoc cref="EntityNotFoundException"/>
        public EntityNotFoundException()
        {

        }

        /// <inheritdoc cref="EntityNotFoundException"/>
        /// <param name="entityType"><inheritdoc cref="EntityType" path="/summary"/></param>
        /// <param name="id"><inheritdoc cref="Id" path="/summary"/></param>
        public EntityNotFoundException(Type entityType, object id) : this(entityType, id, null)
        {

        }

        /// <inheritdoc cref="EntityNotFoundException" path="/summary"/>
        /// <param name="entityType"><inheritdoc cref="EntityType" path="/summary"/></param>
        /// <param name="id"><inheritdoc cref="Id" path="/summary"/></param>
        /// <param name="innerException">表示内部异常/></param>
        public EntityNotFoundException(Type entityType, object id, System.Exception innerException)
            : base($"There is no such an entity. Entity type: {entityType.FullName}, id: {id}", innerException)
        {
            EntityType = entityType;
            Id = id;
        }

        /// <inheritdoc/>
        public EntityNotFoundException(string message) : base(message)
        {

        }

        /// <inheritdoc/>
        public EntityNotFoundException(string message, System.Exception innerException) : base(message, innerException)
        {

        }
    }
}
